import ctypes, sys, os
from future.types.newbytes import unicode


def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False


def getUAC(func):
    """
    This Module can use administrator privileges.
    :param func: accept Function only.
    :return: None
    """
    if is_admin():
        func()
        # 将要运行的代码加到这里
    else:
        if sys.version_info[0] == 3:
            ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
        else:  # in python2.x
            ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)
